package com.example.recordingpen_datacollection.controller;


import com.example.recordingpen_datacollection.entity.Query.LimituseradminQue;
import com.example.recordingpen_datacollection.redisService.RedisService;
import com.example.recordingpen_datacollection.result.RLIST;
import com.example.recordingpen_datacollection.service.LimituseradminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xg
 * @since 2024-06-11
 */
@Api(tags = "配额比例")
@RestController
@RequestMapping("/limituseradmin")
public class LimituseradminController {
    @Autowired
    private LimituseradminService limituseradminService;
    @Autowired
    private RedisService redisService;

    @ApiOperation(value = "查询配额比例")
    @PostMapping("/getLimit")
    public RLIST getLimit(@RequestBody LimituseradminQue limituseradminQue, HttpServletRequest request){
        String token = request.getHeader("token");
        if( !(token.length() == 51 || token.length() == 56) ){
            return RLIST.error().message("无权操作");
        }
        if ((limituseradminQue.getPageNo() == null || limituseradminQue.getPageNo() <=0) ){
            limituseradminQue.setPageNo(1);
        }
        if ((limituseradminQue.getPageSize() == null || limituseradminQue.getPageSize() <=0) ){
            limituseradminQue.setPageSize(10);
        }
        Integer value = (Integer) redisService.getValue(token);
        if(token.length() == 56){
            value = 0;
        }
        return limituseradminService.getLimitPage(limituseradminQue,value);
    }

}

